//
//  Filter.m
//  openJira
//
//  Created by Vincent Demay on 29/04/10.
//  Copyright 2010 Goojet. All rights reserved.
//

#import "OJFilter.h"


@implementation OJFilter
@synthesize lid, name, author, project, description;

- (void) dealloc {
	[lid release];
	[name release];
	[description release];
	[author release];
	[project release];
	[super dealloc];
}


@end


///////////////////////// OJFILTERLIST //////////////////////

@implementation OJFilterList
@synthesize filters, delegate;

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}


- (void) getFavouriteFilters{
	[[OJConnector getDefault] getFavouriteFilters:self];
}


////////////////////////// MANAGE RESPONSES ///////////////////
- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response {
	id fromResponse = [response  object];
	[filters release];
	filters = [[NSMutableArray alloc] init];
	
	for (int i=0; i<[fromResponse count]; i++) {
		OJFilter *filter = [[OJFilter alloc] init];
		filter.name = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"name"];
		filter.description = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"description"];
		filter.lid = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"id"];
		filter.author = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"author"];
		filter.project = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"project"];
		[filters addObject:filter];
		[filter release];
	}
	
	[delegate object:self isReady:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response {
	[delegate object:self isReady:YES];
}

@end

